import express from 'express';
import path from 'path';
import websiteRouter from './routes/website';
import apiRouter from './routes/api';
import { errorHandler } from './middleware/errorHandler';

const app = express();
const port = 3000;

// 静态资源中间件
app.use('/static', express.static(path.join(__dirname, 'client/static')));

// API路由
app.use('/api', apiRouter);

// 网站路由
app.use('/website', websiteRouter);

// 错误处理中间件必须放在所有路由之后
app.use(errorHandler);

// 根路径重定向到website
app.get('/', (req, res) => {
  res.redirect('/website');
});

app.listen(port, () => {
  console.log(`Server is running on http://localhost:${port}`);
}); 